<?php
namespace Common\Model;
use Think\Model;

/**
 * Class MobileAdminModel
 * @package Common\Model
 * 移动端管理员
 */
class MobileAdminModel extends BaseModel{
    public $pix = "";
    public $fieldsStr = '*';
    public $orderStr = 'id desc';

    public function get_list_use_page( $map=array(), $cur_page, $rows_num){
        //区分是否开启缓存，后台的话就不开启，因为实时性较高，前台就开启
        $count = $this->where($map)->count();
        $list = $this->where($map)->order($this->orderStr)->page($cur_page.",$rows_num")->select();
        return array('total'=>$count, 'list'=>$list);
    }

    public function get_tree_show_json($ids=''){
        $ids = explode(',', $ids);
        $return_array = array();
        $map['status'] = 1;
        $list = $this->where($map)->order($this->orderStr)->select();
        foreach($list as $k => $v){
            $temp = array();
            $temp['id'] = $v['id'];
            $temp['text'] = $v['realname'];
            if(in_array($v['id'], $ids)){
                $temp['checked'] = true;
            }
            $return_array[] = $temp;
        }
        return $return_array;
    }

    public function get_names_by_ids($ids){
        $ids = array_filter(explode(',', $ids));
        $push = array();
        foreach($ids as $id){
            $one = $this->queryObj($id, 'id');
            $push[] = $one['realname'].'('.$one['phone'].')';
        }
        return implode(",",$push);
    }

    public function get_working_names_by_ids($ids){
        $sign_model = D('MobileRegest');
        $ids = array_filter(explode(',', $ids));
        $push = array();
        foreach($ids as $id){
            $status = $sign_model->find_last_one_by_user($id);
            if($status==2||$status==-2){
                continue;
            }
            $one = $this->queryObj($id, 'id');
            $push[] = $one['realname'].'('.$one['phone'].')';
        }
        return implode(",",$push);
    }

    /**
     * @param $ids 使用,分割字符串
     * @return array
     *
     */
    public function query_by_ids($ids){
        $ids = array_filter(explode(',', $ids));
        $push = array();
        foreach($ids as $id){
            $one = $this->queryObj($id, 'id');
            $push[] = $one;
        }
        return $push;
    }
}